package com.tanxi521.afkreward;

import com.tanxi521.afkreward.command.AfkCommand;
import com.tanxi521.afkreward.data.AFKRewardMapper;
import com.tanxi521.afkreward.data.ConnectPool;
import com.tanxi521.afkreward.listener.AfkListener;
import com.tanxi521.afkreward.placeholder.AfkPlaceHolder;
import com.tanxi521.afkreward.util.ConfigUtil;
import com.tanxi521.afkreward.util.RewardUtil;
import com.tanxi521.afkreward.util.TimerUtils;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Timer;


public final class AfkReward extends JavaPlugin {

    public static AfkReward instance;

    public static TimerUtils timerUtils;

    public static AfkReward getInstance() {
        return instance;
    }

    @Override
    public void onLoad() {
        instance = this;
        saveDefaultConfig();
    }

    @Override
    public void onEnable() {
        timerUtils = new TimerUtils();
        getLogger().info("§e挂机系统启动中...");
        getLogger().info("§e版本号: " + getDescription().getVersion());
        getLogger().info("§e作者: " + getDescription().getAuthors());
        getLogger().info("§e联系方式: QQ 1254806967");
        AFKRewardMapper.createTable();
        ConfigUtil.initMsg();
        ConfigUtil.initArea();
        ConfigUtil.initPlaceHolder();
        ConfigUtil.checkVersion();
        RewardUtil.updateOfflinePlayerEndTime();
        Bukkit.getPluginCommand("tnafk").setExecutor(new AfkCommand());
        Bukkit.getPluginManager().registerEvents(new AfkListener(), this);
    }

    @Override
    public void onDisable() {
        RewardUtil.updateOfflinePlayerEndTime();
//        ConnectPool.close(ConnectPool.pool);
        AFKRewardMapper.AFK_MAP.clear();
        PlaceholderAPI.unregisterPlaceholderHook("the");
    }
}
